<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

namespace app\admin\model;

use think\Model;
use think\Db;

/**
 * 车型系列
 * @package app\admin\model
 */
class SeriesModel extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'e_series';
	
	/**
     * 获取系列列表
     * @param int $page 当前分页
	 * @param int $export 是否导出
     * @param string $keyword 搜索关键字
     * @author 郑义生 <1052063941@qq.com>
     * @return mixed
     */
	public function getSeriesList($input)
	{
		$query = Db::name($this->table)->where('series_status','in','[0,1]');
		$page = isset($input['page']) ? $input['page'] : 1;
		$export = isset($input['export']) ? $input['export'] : 0;
		$order_field = isset($input['order_field']) ? $input['order_field'] : '';
		$order_value = isset($input['order_value']) ? $input['order_value'] : 'desc';
		if(isset($input['id']) && !empty($input['id'])){
			$query = $this->where('id',$input['id']);
		}
		if(isset($input['field_id']) && !empty($input['field_id'])){
			$query = $this->where('field_id',$input['field_id']);
		}
		if(isset($input['country_id']) && !empty($input['country_id'])){
			$query = $this->where('country_id',$input['country_id']);
		}
		if(isset($input['make_id']) && !empty($input['make_id'])){
			$query = $this->where('make_id',$input['make_id']);
		}
		if(isset($input['f_c_id']) && !empty($input['f_c_id'])){
			$query = $this->where('f_c_id',$input['f_c_id']);
		}
		if(isset($input['keyword']) && !empty($input['keyword'])){
			$query = $this->where('series_code|series_name','like','%'.$input['keyword'].'%');
		}
		$order_arr = ['id'=>'desc'];
		if(!empty($order_field)){
			$order_arr = [$order_field=>$order_value];
		}
		if($export){
			$list = $query->order($order_arr)->select();
			return [
				'list'=>$list,
				'page'=>array()
			];
		}else{
			$list = $query->order($order_arr)->paginate(config('paginate.list_rows'));
			$page = $list->render();
			return [
				'list'=>$list->toArray(),
				'page'=>$page
			];
		}
	}
}
